---
layout : doc
title : Hosting Phoenix
permalink: docs\HostingPhoenix.html
---

One of the great things about Phoenix is you do not have to use it completely. I decided that some application's are not very navigation heavy, or they are existing, and Phoenix could really benefit a single view/section of the application. So we made it easy to start hosting Phoenix in any view in your application.

## Phoenix Host

Phoenix includes a default `PhoenixApplicationHostTarget` which is the base class for `PhoenixApplication` and is responsible for setting up and hosting your application entirely in Phoenix (default behaviour).

If you would like to create your own Phoenix host, which could be a `UserControl` or a `Window`, simply inherit from `IPhoenixHostTarget`, a sample implementation would be:

    public class PhoenixHostControl : UserControl, IPhoenixHostTarget
    {
        public PhoenixHostControl()
        {
            Background = Brushes.White;
        }

        public void Show(INavigationFrame navigationFrame)
        {
            NavigationFrame = navigationFrame;
            Content = navigationFrame;
        }

        public INavigationFrame NavigationFrame { get; private set; }

        public Control ContentHost
        {
            get { return this; }
        }
    }
    
And now we need to use a PhoenixHostBuilder, (the Autofac extension contains a `AutofacPhoenixHostBuilder` which gives you autofac support).

    var phoenixHostBuilder = new AutofacPhoenixHostBuilder(
       TaskScheduler.FromCurrentSynchronisationContext(),
       Dispatcher);

    phoenixHostBuilder.SetNavigationFrameFactory(() => new TransitionNavigationFrame());
    phoenixHostBuilder.Configuration.DefaultControllerAction = "Home.Main";

    var hostTarget = new PhoenixHostControl();
    phoenixHostBuilder.Run(hostTarget, context.Container)
        .ContinueWith(t =>
        {
            //Handle any startup errors
        });
        
    var frameworkElement = hostTarget.ContentHost; //You should use ContentHost, as the hostTarget is not guarenteed to be a user control/window.
	
This is all that is needed to host Phoenix in any part of your application. 